#!/bin/sh
start_time=$(date +%s)
du -h -d0
rm -rf ../utf ../gbk
find -type d -exec mkdir -p ../utf/{} \;
find -type f -name "*.h*" -exec iconv -f gb18030 -t utf-8 {} -o ../utf/{} \;
find -type f -name "*.c*" -exec iconv -f gb18030 -t utf-8 {} -o ../utf/{} \;
find -type f -name "*.inl" -exec iconv -f gb18030 -t utf-8 {} -o ../utf/{} \;
cd ../utf
du -h -d0
find -type f -name "*.h*" -exec sed -i '/^[ \t]*\/\//d' {} \;
find -type f -name "*.h*" -exec sed -i 's/\/\/[^"]*$//g' {} \;
find -type f -name "*.h*" -exec sed -i 's/\/\*[^\/]*\*\///g;s/\/\*.*\*\///g;s/.+\/\*/\n\/\*/g' {} \;
find -type f -name "*.h*" -exec sed -i '/^[ \t]*\/\*/,/.*\*\//d' {} \;
find -type f -name "*.h*" -exec sed -i 's/[ \t\r\n]*$//g;/./,/^$/!d' {} \;
find -type f -name "*.c*" -exec sed -i '/^[ \t]*\/\//d' {} \;
find -type f -name "*.c*" -exec sed -i 's/\/\/[^"]*$//g' {} \;
find -type f -name "*.c*" -exec sed -i 's/\/\*[^\/]*\*\///g;s/\/\*.*\*\///g;s/.+\/\*/\n\/\*/g' {} \;
find -type f -name "*.c*" -exec sed -i '/^[ \t]*\/\*/,/.*\*\//d' {} \;
find -type f -name "*.c*" -exec sed -i 's/[ \t\r\n]*$//g;/./,/^$/!d' {} \;
find -type f -name "*.inl" -exec sed -i '/^[ \t]*\/\//d' {} \;
find -type f -name "*.inl" -exec sed -i 's/\/\/[^"]*$//g' {} \;
find -type f -name "*.inl" -exec sed -i 's/\/\*[^\/]*\*\///g;s/\/\*.*\*\///g;s/.+\/\*/\n\/\*/g' {} \;
find -type f -name "*.inl" -exec sed -i '/^[ \t]*\/\*/,/.*\*\//d' {} \;
find -type f -name "*.inl" -exec sed -i 's/[ \t\r\n]*$//g;/./,/^$/!d' {} \;
find -type d -exec mkdir -p ../gbk/{} \;
find -type f -name "*.h*" -exec iconv -f utf-8 -t gb18030 {} -o ../gbk/{} \;
find -type f -name "*.c*" -exec iconv -f utf-8 -t gb18030 {} -o ../gbk/{} \;
find -type f -name "*.inl" -exec iconv -f utf-8 -t gb18030 {} -o ../gbk/{} \;
cd ../gbk
du -h -d0
end_time=$(date +%s)
elapsed_time=$((end_time - start_time))
echo "脚本执行耗时：$elapsed_time 秒"



#先删除行尾空格，再删除连续多个空白行仅保留一个空白行
find -type f -name "*.h" -exec sed -i 's/[ \t\r\n]*$//g;/./,/^$/!d' {} \;

sed匹配中文时必须使用操作系统的utf-8编码，否则无法正确查找
#目录批量处理
find -type d -exec mkdir -p ../utf/{} \;
#文件批量处理
find -type f -exec iconv -f gb18030 -t utf-8 {} -o ../utf/{} \;

find -type d -exec mkdir -p ../gbk/{} \;
find -type f -exec iconv -f utf-8 -t gb18030 {} -o ../gbk/{} \;


sed匹配必须使用/符号，替换s可以使用其它几乎所有符号，
find -type f -name "*.h*" -exec sed -i 's/\/\*[^\/]*\*\///g;s/\/\*.*\*\///g;s/.+\/\*/\n\/\*/g' {} \;
也可以写成*必须转义/就可以写成原样
find -type f -name "*.h*" -exec sed -i 's|/\*[^\/]*\*/||g;s|/\*.*\*/||g;s|.+/\*|\n/\*|g' {} \;
不可以写成
find -type f -name "*.h*" -exec sed -i 's|/*[^\/]**/||g;s|/*.**/||g;s|.+/*|\n/*|g' {} \;
